package com.cloud.magic_api.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.common.domain.Result;
import com.cloud.magic_api.entity.SysUserInfo;
import com.cloud.magic_api.mapper.SysUserInfoMapper;
import com.cloud.magic_api.service.IUserInfoService;
import com.cloud.utils.StringUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 开发账户信息
 *
 * @author yzj
 * @since 2022-08-26
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUserInfo> implements IUserInfoService {

    @Resource
    private SysUserInfoMapper sysUserInfoMapper;

    /**
     * 开发账户信息分页
     *
     * @author yzj
     */
    @Override
    public List<SysUserInfo> selectUserList(SysUserInfo userInfo) {
        return sysUserInfoMapper.selectUserList(userInfo);
    }

    /**
     * 开发账户信息新增
     *
     * @author yzj
     */
    @Override
    public Result insertObject(SysUserInfo userInfo) {
        if (StringUtils.isNotEmpty(userInfo.getPassword())) {
            userInfo.setPassword(SecureUtil.md5(userInfo.getPassword()));
        }
        sysUserInfoMapper.insert(userInfo);
        return Result.success("操作成功");
    }

    /**
     * 开发账户信息修改
     *
     * @author yzj
     */
    @Override
    public Result updateObject(SysUserInfo userInfo) {
        if (StringUtils.isNotEmpty(userInfo.getPassword())) {
            userInfo.setPassword(SecureUtil.md5(userInfo.getPassword()));
        }
        sysUserInfoMapper.updateById(userInfo);
        return Result.success("操作成功");
    }

    /**
     * 修改开发账户状态
     *
     * @param state
     * @param userId
     * @return
     */
    @Override
    public int updateUserState(String state, Long userId) {
        return sysUserInfoMapper.updateUserState(state, userId);
    }

}
